/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.pdx.cs.guavadata.query;

import edu.pdx.cs.guavadata.Channel;
import edu.pdx.cs.guavadata.Transform;

/**
 *
 * @author VuTran
 */
public class Error extends Operator {

    // DDl statement for a generic check constraint (Tier 3 foreign key)

    Operator query;

    public Operator getQuery() {
        return query;
    }

    public void setQuery(Operator query) {
        this.query = query;
    }

    public Error(Operator query) {
        try {
            if (!query.isQuery())
                throw new Exception("Cannot perform an error check on objects that are not queries.");
        } catch (Exception ex) {
            System.err.println("ERROR: " + ex.toString());
        }
        this.query = query;
    }

    @Override
    public void notifyChange(Operator old, Operator newOp) {
        if (this.query == old)
            this.query = newOp;
    }

    @Override
    public boolean isQuery() {
        return false;
    }

    @Override
    public SqlText visit(Provider qv) {
        return qv.transform(this);
    }

    @Override
    public void visit(Channel c, String table) {
        c.mapAliases(this, table);
    }

    @Override
    public void visit(Transform t, Command c) {
        t.expand(this, c);
    }

    @Override
    public Operator clone() {
        return new Error(this.query.clone());
    }

}
